import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:wallet/common/common.dart';
import 'package:wallet/generated/l10n.dart';
import 'package:wallet/pages/mine/about_page.dart';
import 'package:wallet/pages/mine/contacts_page.dart';
import 'package:wallet/pages/mine/invite_friends_page.dart';
import 'package:wallet/pages/mine/settings_page.dart';
import 'package:wallet/pages/mine/transactions_page.dart';
import 'package:wallet/pages/mine/wallet_management_page.dart';
import 'package:wallet/widget/BaseViewBar.dart';

class MinePage extends StatefulWidget {
  @override
  _MinePageState createState() => _MinePageState();
}

class _MinePageState extends State<MinePage> {
  List<Item> getList(BuildContext context) {
    return [
      Item(S.of(context).wallet_management, onTap: () {
        Navigator.of(context).push(MaterialPageRoute(
            builder: (BuildContext context) => WalletManagementPage()));
      }),
      Item(S.of(context).transactions, onTap: () {
        Navigator.of(context).push(MaterialPageRoute(
            builder: (BuildContext context) => TransactionsPage()));
      }),
      Item(S.of(context).contacts, onTap: () {
        Navigator.of(context).push(MaterialPageRoute(
            builder: (BuildContext context) => ContactsPage()));
      }),
      Item(S.of(context).invite_friends, onTap: () {
        Navigator.of(context).push(MaterialPageRoute(
            builder: (BuildContext context) => InviteFriendsPage()));
      }),
      Item(S.of(context).system_settings, onTap: () {
        Navigator.of(context).push(MaterialPageRoute(
            builder: (BuildContext context) => SettingsPage()));
      }),
      Item(S.of(context).about_us, onTap: () {
        Navigator.of(context).push(
            MaterialPageRoute(builder: (BuildContext context) => AboutPage()));
      }),
      Item(S.of(context).sign_out, onTap: () {}),
    ];
  }

  Widget _itemWidget(BuildContext context, int index) {
    return Container(
      decoration: BoxDecoration(
          border: Border(
              bottom: BorderSide(
                  width: index == 1 || index == 2 ? 10 : 1,
                  color: Colors.black12))),
      child: ListTile(
          title: Text(getList(context)[index].title),
          trailing: getList(context)[index].onTap == null
              ? Text("")
              : Icon(Icons.arrow_forward_ios),
          onTap: getList(context)[index].onTap),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: BaseViewBar(
          preferredSize: Size.fromHeight(50.0),
          child: BaseTitleBar(
            S
                .of(context)
                .personal_center,
            showLeading: false,
          ),
        ),
        body: ListView.builder(
            itemCount: getList(context).length, itemBuilder: (context, index) {
          return _itemWidget(context, index);
        })
    );
  }
}
